package com.blb.zycommunity.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blb.zycommunity.entity.ResponseResult;
import com.blb.zycommunity.entity.ZyComplaintSuggest;
import com.blb.zycommunity.entity.ZyOwner;
import com.blb.zycommunity.service.IZyComplaintSuggestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;


/**
 * <p>
 * 投诉建议  前端控制器
 * </p>
 *
 * @author chenheng
 * @since 2023-11-20
 */
@CrossOrigin
@RestController
public class ZyComplaintSuggestController {

    @Autowired
    private IZyComplaintSuggestService zyComplaintSuggestService;

    @GetMapping("/suggest-pages")
    public ResponseResult<IPage<ZyOwner>> findOwnerPage(@RequestParam(required = false,defaultValue = "1") Long current,
                                                        @RequestParam(required = false,defaultValue = "5") Long size,
                                                        @RequestParam(required = false) String complaintSuggestType,
                                                        @RequestParam(required = false) String communityId){
        IPage<ZyComplaintSuggest> complaintSuggestPage = zyComplaintSuggestService.findComplaintSuggestPage(current, size, complaintSuggestType, communityId);
        return ResponseResult.ok(complaintSuggestPage);
    }

    @PostMapping("/uni-app/suggest-add")
    public ResponseResult SuggestAdd(@RequestBody  ZyComplaintSuggest zyComplaintSuggest) {
        zyComplaintSuggest.setCreateTime(LocalDateTime.now());
        zyComplaintSuggestService.save(zyComplaintSuggest);
        return ResponseResult.ok("ok");
    }


    @PutMapping("/suggest-update")
    public ResponseResult updateZyUnit(@RequestBody ZyComplaintSuggest zyComplaintSuggest){
        zyComplaintSuggestService.updateById(zyComplaintSuggest);
        return ResponseResult.ok("ok");
    }

    @GetMapping("/uni-app/suggest-list/{createBy}")
    public ResponseResult<IPage<ZyOwner>> findByName(@PathVariable String createBy){
        List<ZyComplaintSuggest> zyComplaintSuggests = zyComplaintSuggestService.selectByName(createBy);
        return ResponseResult.ok(zyComplaintSuggests);
    }
    @GetMapping("/uni-app/suggest-ByList")
    public ResponseResult<IPage<ZyComplaintSuggest>> findByA(){
        List<ZyComplaintSuggest> zyComplaintSuggests = zyComplaintSuggestService.list();
        return ResponseResult.ok(zyComplaintSuggests);
    }

    @DeleteMapping("/uni-app/suggest-delete/{complaintSuggestId}")
    public ResponseResult findByDelete(@PathVariable Long  complaintSuggestId){
        zyComplaintSuggestService.removeById(complaintSuggestId);
        return ResponseResult.ok("ok");
    }

}
